package server;

import java.rmi.RemoteException;
import java.util.UUID;

public class ClientWrapper {

	//ATTRIBUTES: start
	private String ipAddress;

	public String getIpAddress() {
		return ipAddress;
	}

	public void setIpAddress(String ipAddress) {
		this.ipAddress = ipAddress;
	}

	private String port;

	public String getPort() {
		return port;
	}

	public void setPort(String port) {
		this.port = port;
	}

	private client.ICallbackHandler callbackHandler;

	public client.ICallbackHandler getCallbackHandler() {
		return callbackHandler;
	}

	public void setCallbackHandler(client.ICallbackHandler callbackHandler) {
		this.callbackHandler = callbackHandler;
	}

	private UUID uniqueIdentifier;
	
	public UUID getUniqueIdentifier() {
		return uniqueIdentifier;
	}

	public void setUniqueIdentifier(UUID uniqueIdentifier) {
		this.uniqueIdentifier = uniqueIdentifier;
	}
	
	private int lockedCellAbscissa;
	
	public int getLockedCellAbscissa() {
		return lockedCellAbscissa;
	}
	public void setLockedCellAbscissa(int lockedCellAbscissa) {
		this.lockedCellAbscissa = lockedCellAbscissa;
	}
	
	private int lockedCellOrdinate;
	
	public int getLockedCellOrdinate() {
		return lockedCellOrdinate;
	}

	public void setLockedCellOrdinate(int lockedCellOrdinate) {
		this.lockedCellOrdinate = lockedCellOrdinate;
	}
	//ATTRIBUTES: end
	
	public ClientWrapper(final String _ipAddress, final String _port,
			final client.ICallbackHandler _callbackHandler, final UUID _uniqueIdentifier) {
		this.setIpAddress(_ipAddress);
		this.setPort(_port);
		this.setCallbackHandler(_callbackHandler);
		this.setUniqueIdentifier(_uniqueIdentifier);
	}

	public void notifyMe(String message) throws RemoteException {

		this.getCallbackHandler().notifyMe(message);
	}
	
	public void updateCellValue(String value, int abscissa, int ordinate) {
		try {
			
			//********
			String result = this.getCallbackHandler().updateCellValue(abscissa, ordinate, value);			
			//this.getCallbackHandler().notifyMe(String.format("A celula na posicao [%s,%s] devera assumir o valor: %s", abscissa, ordinate, value ));
		
		} catch (RemoteException e) {
			
			e.printStackTrace();
		}
	}
	
	public void lockCell(int abscissa, int ordenata) {
		try {
			
			this.getCallbackHandler().lockCell(abscissa, ordenata);
			
		} catch (Exception e) {
			
			e.printStackTrace();
		}
	}
}
